From 3b7bd625ca25efaa92ea6fb4bcfb317e7d816882 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 13 Jan 2010 22:52:52 +0000 Subject: [PATCH] More checking for invalid/corrupt GDB files. --- gdb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gdb.c b/gdb.c index 364e16af1..50e8171d2 100644 --- a/gdb.c +++ b/gdb.c @@ -110,8 +110,8 @@ /*******************************************************************************/ -/* static char gdb_release[] = "$Revision: 1.69 $"; */ -static char gdb_release_date[] = "$Date: 2009/06/23 03:29:25 $"; +/* static char gdb_release[] = "$Revision: 1.70 $"; */ +static char gdb_release_date[] = "$Date: 2010/01/13 22:52:52 $"; static gbfile *fin, *fout, *ftmp; static int gdb_ver, gdb_category, gdb_via, gdb_roadbook; @@ -995,7 +995,9 @@ read_data(void) route_head *trk, *rte; len = FREAD_i32; - FREAD(&typ, 1); + if (FREAD(&typ, 1) < 1) { + fatal(MYNAME ": Attempt to read past EOF."); + } if (typ == 'V') break; /* break the loop */ gbfrewind(ftmp); @@ -1037,6 +1039,10 @@ read_data(void) fin = fsave; delta = len - gbftell(ftmp); + // Avoid finite loop on bogus beta files from '06. + // THe 100000 is totally pulled from my hat. + // is_fatal((delta > 1000000) || (delta < 0), "Internal GDB error; invalid delta."); + if (dump && delta) { if (! incomplete++) { warning(MYNAME ":==========================================\n"); @@ -1050,7 +1056,8 @@ read_data(void) if (delta > 0) { int i; char *buf = xmalloc(delta); - FREAD(buf, delta); + if (FREAD(buf, delta) < 1) + fatal(MYNAME ": Attempt to read past EOF.\n"); for (i = 0; i < delta; i++) { warning(" %02x", (unsigned char)buf[i]); } -- 2.30.2